package com.example.myapplication.fragment

import com.example.myapplication.my_view_model.NavViewModel
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.SeekBar
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController
import androidx.navigation.Navigation
import com.example.myapplication.R
import com.example.myapplication.databinding.FragmentHomeBinding

class HomeFragment : Fragment() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {

        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        var viewModel: NavViewModel? = activity?.let {
            ViewModelProvider(it)[NavViewModel::class.java]
        }
        var binding = DataBindingUtil.inflate<FragmentHomeBinding>(inflater,R.layout.fragment_home,container,false)
        binding.data = viewModel
        binding.lifecycleOwner = activity
        if (viewModel != null) {
            binding.seekBar3.progress = viewModel.scoreData.value!!
        }
        binding.seekBar3.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                viewModel?.reset(progress)
            }
            override fun onStartTrackingTouch(seekBar: SeekBar?) {
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
            }
        })
        binding.button17.setOnClickListener(object : View.OnClickListener{
            override fun onClick(v: View?) {
                val controller: NavController = Navigation.findNavController(v!!)
                container
                controller.navigate(R.id.action_homeFragment5_to_detailFragment3)
            }
        })
        return binding.root
    }

}